import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { withRouter, Link } from 'react-router-dom';
import axios from 'axios';
import Switch from 'rc-switch';
import { GLOBAL_SETTINGS } from '../../containers/SettingPage/settingReducer';
import './styles.scss';
import Button from '../Button';
import Modal from '../Modal';
import { List, Avatar, Badge } from 'antd';

function openRepoUrl(history) {
  if (process.env.NODE_ENV === 'production') {
    history.push('/group_chat/ddbffd80-3663-11e9-a580-d119b23ef62e');
  } else {
    window.open('https://im.aermin.top/group_chat/ddbffd80-3663-11e9-a580-d119b23ef62e');
  }
}

const data = [
  {
    title: '好友申请信息',
    url: '/notify/private_chat/apply',
  },
  {
    title: '群申请信息',
    url: '/notify/group_chat/apply',
  },
];

function Setting({ initApp, history, globalSettings, setGlobalSettings }) {
  const [logoutModalVisible, setLogoutModalVisible] = useState(false);
  const [githubStars, setGithubStars] = useState('--');

  const logout = () => {
    window.socket.disconnect();
    localStorage.removeItem('userInfo');
    initApp(false);
    history.push('/login');
  };

  useEffect(() => {
    axios.get('https://api.github.com/repos/aermin/ghChat').then(res => {
      setGithubStars(res.data.stargazers_count);
    });
  });

  const _onChange = (type, value) => {
    setGlobalSettings({
      [type]: value,
    });
  };

  return (
    <div className="notify">
      <List
        itemLayout="horizontal"
        dataSource={data}
        renderItem={item => (
          <List.Item className="item">
            <List.Item.Meta
              title={<Link to={item.url}>{item.title}</Link>}
            />
          </List.Item>
        )}
      />
      ,
    </div>
  );
}

Setting.propTypes = {
  initApp: PropTypes.func,
  history: PropTypes.object.isRequired,
  globalSettings: PropTypes.object,
  setGlobalSettings: PropTypes.func,
};

Setting.defaultProps = {
  initApp() {},
  globalSettings: {},
  setGlobalSettings() {},
};

export default withRouter(Setting);
